package com.fjc.controller.admin;

import com.fjc.dto.MedicineDTO;
import com.fjc.dto.MedicinePageQueryDTO;
import com.fjc.result.PageResult;
import com.fjc.result.Result;
import com.fjc.service.MedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 药品管理
 */
@RestController
@RequestMapping("/admin/medicine")
@Api(tags = "药品相关接口")
@Slf4j
public class MedicineController {

    @Autowired
    private MedicineService medicineService;

    /**
     * 新增药品
     * @param medicineDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增药品")
    public Result save(@RequestBody MedicineDTO medicineDTO) {
        log.info("新增药品:{}", medicineDTO);
        medicineService.save(medicineDTO);
        return Result.success();
    }

    /**
     * 药品分页查询
     * @param medicinePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("药品分页查询")
    public Result<PageResult> page(MedicinePageQueryDTO medicinePageQueryDTO) {
        log.info("药品分页查询{}", medicinePageQueryDTO);
        PageResult pageResult = medicineService.pageQuery(medicinePageQueryDTO);
        return Result.success(pageResult);
    }


}
